package com.wwwarehouse.usercenter.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.wwwarehouse.common.tools.ImageloaderUtils;
import com.wwwarehouse.usercenter.R;
import com.wwwarehouse.usercenter.bean.BusinessInfo;

import java.util.List;


public class BusinessInfoAdapter extends BaseAdapter {

    private List<BusinessInfo> mData;
    private Context mContext;
    private ViewHolder mHolder;

    public BusinessInfoAdapter(List<BusinessInfo> data, Context context) {
        this.mData = data;
        this.mContext = context;
    }

    @Override
    public int getCount() {
        return mData == null ? 0 : mData.size();
    }

    @Override
    public Object getItem(int position) {
        return mData.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = View.inflate(mContext, R.layout.item_business_info, null);
            mHolder = new ViewHolder(convertView);
            convertView.setTag(mHolder);
        } else {
            mHolder = (ViewHolder) convertView.getTag();
        }
        mHolder.mCompanyName.setText(mData.get(position).getBuName());
        ImageloaderUtils.displayImg(ImageloaderUtils.getImageLoader(),mData.get(position).getBuIcon(), mHolder.mCompanyImage,ImageloaderUtils.initImageLoaderOption(R.drawable.create_business_logo,R.drawable.create_business_logo),new ImageloaderUtils.AnimateFirstDisplayListener());
        return convertView;
    }

    class ViewHolder {
        ImageView mCompanyImage;
        TextView mCompanyName;

        public ViewHolder(View view) {
            mCompanyImage = (ImageView) view.findViewById(R.id.item_icon);
            mCompanyName = (TextView) view.findViewById(R.id.item_name);
        }
    }
}
